package seqAlignment.utils;

import java.awt.Point;

import seqAlignment.AffineGPPoint;

public class MatrixOut {
	public MatrixOut() {}
	public static void out(int[][] matrix) {
		String[] out = new String[matrix[0].length];
		for (int x=0;x<matrix.length; x++) {
			for (int y=0; y<matrix[x].length; y++) {
				if (out[y]==null) {
					out[y]= "";
				}
				out[y]=out[y]+ intToString( matrix[x][y])+"\t";
			}
		}
		outArray(out);
	}
	
	public static void out(Point[][] path) {
	}
	
	public static void out(Point[][] path, Point[][] pathX, Point[][] pathY) {
		System.out.println("path");
		outHelp(path, path, pathX, pathY);
		System.out.println("pathX");
		outHelp(pathX, path, pathX, pathY);		
		System.out.println("pathY");
		outHelp(pathY, path, pathX, pathY);
	}
	
	public static void out(Point[][][] AllPath, Point[][][] AllPathX, Point[][][] AllPathY, Point[][] path, Point[][] pathX, Point[][] pathY) {
		System.out.println("path");
		outHelp(AllPath, path, pathX, pathY);
		System.out.println("pathX");
		outHelp(AllPathX, path, pathX, pathY);
		System.out.println("pathY");
		outHelp(AllPathY, path, pathX, pathY);
	}
	
	protected static void outHelp(Point[][][] toOut, Point[][] path, Point[][] pathX, Point[][] pathY) {
		String[] out=new String[toOut[0].length*3];
		for (int x=0; x<toOut.length; x++) {
			for (int y=0; y<toOut[x].length; y++) {
				for (int i=0;i<toOut[x][y].length; i++) {
					int ln=y*3+i;
					if (out[ln]==null) {
						out[ln]="";
					}
					out[ln]+=pointToStr((AffineGPPoint)toOut[x][y][i], path, pathX, pathY);
				}
			}
		}
		outArray(out);
	}
	
	protected static void outHelp(Point[][] toOut, Point[][] path, Point[][] pathX, Point[][] pathY) {
		String[] out=new String[toOut[0].length];
		for (int x=0; x<toOut.length; x++) {
			for (int y=0; y<toOut[x].length; y++) {
				if (out[y]==null) {
					out[y]="";
				}
				out[y]+=pointToStr((AffineGPPoint)toOut[x][y], path, pathX, pathY);
			}
		}
		outArray(out);
	}
	
	protected static String pointToStr(AffineGPPoint point, Point[][] path, Point[][] pathX, Point[][] pathY) {
		String pathName="";
		if (point==null) {
			return "NULL       \t";
		}
		if (point.getPath()==path) {
			pathName="m";
		}
		else if (point.getPath()==pathX) {
			pathName="x";
		}
		else if (point.getPath()==pathY) {
			pathName="y";
		}
		return pathName+","+point.getX()+","+point.getY()+"\t";
	}
	
	protected static void outArray(String[] out) {
		for (int x=0;x<out.length; x++) {
			System.out.println(out[x]);
		}		
	}
	
	protected static String intToString(int val) {
		if (val==Integer.MIN_VALUE) {
			return "-INF";
		}
		else if (val==Integer.MAX_VALUE) {
			return "+INF";
		}
		return ""+val;
	}
}
